package avicit.bdp.dgs.mdm.utils.api.header;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import java.util.ArrayList;
import java.util.List;

public class PostHeaderAdapter extends HeaderAdapter {

    private static final Logger LOG = LoggerFactory.getLogger(PostHeaderAdapter.class);

    private static PostHeaderAdapter instance;

    private PostHeaderAdapter() {
    }

    public synchronized static PostHeaderAdapter instance() {
        if (instance == null) {
            instance = new PostHeaderAdapter();
        }
        return instance;
    }

    /**
     * 构建Header请求头信息
     * @return
     */
    public Object buildHttpEntity(String applicationCode, String authCode, String logId, String data){
        // 创建一个头部对象
        HttpHeaders headers = new HttpHeaders();

        List<MediaType> mediaTypeList = new ArrayList<>();
        mediaTypeList.add(MediaType.ALL);
        headers.setAccept(mediaTypeList);

        headers.add("applicationCode", applicationCode);
        headers.add("authCode", authCode);
        headers.add("logId", logId);
        headers.setContentType(MediaType.valueOf("application/json;charset=UTF-8"));
        return new HttpEntity<Object>(data, headers);
    }

}
